from django.db import models

# Create your models here.
from visitApi.ext.FilterFileField import FilterFileField


class User(models.Model):
    gender = [
        (0, '保密'),
        (1, '男'),
        (2, '女'),
    ]
    userId = models.CharField(max_length=20, verbose_name='用户Id')
    password = models.CharField(max_length=20, verbose_name='密码')
    job = models.CharField(max_length=20, verbose_name='职业')
    nickName = models.CharField(max_length=20, verbose_name='昵称')
    sex = models.SmallIntegerField(choices=gender, default=0, verbose_name='性别')
    phoneNumber = models.CharField(max_length=11, verbose_name='手机号')
    userIcon = models.ImageField(upload_to='image/user/',null=True,blank=True, verbose_name='头像')
    registerDate = models.DateTimeField(auto_now=True, verbose_name='注册时间')
    area = models.TextField(null=True, blank=True, verbose_name='地址')

    class Meta:
        verbose_name = '用户信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.nickName


class Shop(models.Model):
    name = models.CharField(max_length=128, verbose_name='店面名称')
    shopId = models.CharField(max_length=11, verbose_name='店面 ID 编号 ')
    location = models.CharField(max_length=255, verbose_name='店面地址')
    createDate = models.DateTimeField(auto_created=True, verbose_name='创店日期')

    class Meta:
        verbose_name = '店面表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.shopId


class Visit(models.Model):
    shopId = models.ForeignKey(Shop,on_delete=models.CASCADE, verbose_name='店面ID编号')
    shopName = models.CharField(max_length=10, verbose_name='店面名称')
    # 等级格式5,5,5
    shopLevel = models.CharField(max_length=10, verbose_name='巡店打分')
    shopAddress = models.CharField(max_length=10, verbose_name='店面地址')
    user = models.ForeignKey(User, null=True, on_delete=models.CASCADE, verbose_name='用户信息')
    visitDate = models.DateTimeField(auto_now=True, verbose_name='巡店日期')
    imgName = models.CharField(max_length=10, null=True, blank=True, verbose_name='巡店图片名称')
    feedback = models.TextField(verbose_name='巡店反馈意见')
    imgPath1 = models.ImageField(upload_to='image/visit/', null=True, blank=True, verbose_name='巡店图1')
    imgPath2 = models.ImageField(upload_to='image/visit/', null=True, blank=True, verbose_name='巡店图2')
    imgPath3 = models.ImageField(upload_to='image/visit/', null=True, blank=True, verbose_name='巡店图3')

    class Meta:
        verbose_name = '巡店数据表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.shopName


class Info(models.Model):
    t = [
        (0, '公司动态'),
        (1, '行业资讯'),
    ]
    title = models.CharField(max_length=128, verbose_name='资讯标题')
    summary = models.TextField(verbose_name='资讯摘要')
    imgUrl = models.ImageField(upload_to='image/info/', verbose_name='资讯缩率图')
    detail = models.CharField(max_length=255, verbose_name='资讯详情地址')
    type = models.SmallIntegerField(choices=t, verbose_name='资讯类型')

    class Meta:
        verbose_name = '资讯表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class AppInfo(models.Model):
    updateType = [
        (True, '自动下载'),
        (False, '手动下载'),
    ]
    version = models.CharField(max_length=8, verbose_name='版本号')
    publishDate = models.DateTimeField(auto_now=True, verbose_name='发布日期')
    updateInfo = models.TextField(verbose_name='更新说明')
    downloadUrl = FilterFileField(content_types=['application/vnd.android.package-archive', ], max_upload_size=52428800,
                                  upload_to="apk/", verbose_name='应用程序')
    force = models.BooleanField(default=False, choices=updateType, verbose_name='更新方式')

    class Meta:
        verbose_name = 'APP 版本表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f'{self.id}-{self.version}'


class Task(models.Model):
    stateChoices = [
        (0, '执行中'),
        (1, '已完成'),
    ]
    title = models.CharField(max_length=128, verbose_name='任务标题')
    detail = models.CharField(max_length=128, verbose_name='任务详情描述')
    publishDate = models.DateTimeField(auto_created=True, verbose_name='发布日期')
    executeDate = models.DateTimeField(auto_now=True, verbose_name='执行期限')
    state = models.SmallIntegerField(choices=stateChoices, verbose_name='任务状态')

    class Meta:
        verbose_name = '任务表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Customer(models.Model):
    phone = models.CharField(max_length=11, verbose_name='电话')
    company = models.CharField(max_length=11, verbose_name='公司')
    job = models.CharField(max_length=11, verbose_name='职务')
    name = models.CharField(max_length=11, verbose_name='姓名')

    class Meta:
        verbose_name = '拜访客户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Interview(models.Model):
    title = models.CharField(max_length=64, verbose_name='拜访标题')
    visitDate = models.DateTimeField(auto_now=True, verbose_name='拜访日期')
    customer = models.ForeignKey(Customer, null=True, on_delete=models.CASCADE, verbose_name='拜访目标')
    aim = models.CharField(max_length=128, verbose_name='拜访目的')
    summary = models.TextField(verbose_name='拜访总结')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='拜访人信息')

    class Meta:
        verbose_name = '拜访表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Train(models.Model):
    title = models.CharField(max_length=64, verbose_name='培训标题')
    date = models.DateTimeField(auto_now=True, verbose_name='培训日期')
    location = models.CharField(max_length=64, verbose_name='培训地址')
    trainer = models.CharField(max_length=16, verbose_name='培训讲师')
    trainId = models.CharField(max_length=16, verbose_name='培训编号')

    class Meta:
        verbose_name = '培训任务表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Traindata(models.Model):
    score = models.CharField(max_length=6, verbose_name='培训打分')
    feedback = models.TextField(verbose_name='培训反馈')
    imgPath = models.CharField(max_length=255, verbose_name='培训图片地址')
    imgName = models.CharField(max_length=64, verbose_name='图片名称')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='培训提交人')
    train = models.ForeignKey(Train, on_delete=models.CASCADE, verbose_name='培训任务ID')

    class Meta:
        verbose_name = '培训任务表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Feedback(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='反馈提交人员')
    date = models.DateTimeField(auto_now=True, verbose_name='提交日期')
    feedback = models.TextField(verbose_name='反馈意见')

    class Meta:
        verbose_name = '反馈意见表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.nickName


class Announcement(models.Model):
    stateChoices = [
        (0, '使用中'),
        (1, '已废弃'),
    ]
    imgUrl = models.ImageField(upload_to='image/banner/', verbose_name='轮播图')
    detailUrl = models.CharField(max_length=128, verbose_name='公告详情链接')
    createDate = models.DateTimeField(auto_now=True, verbose_name='公告创建日期')
    state = models.SmallIntegerField(choices=stateChoices, verbose_name='广告公告状态')

    class Meta:
        verbose_name = '商品信息轮播图表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return ("轮播图%s" % self.id)
